home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / ja91 / ASCII / ManWindows / ManWindows.txt
Encoding:
Text File  |  1991-08-09  |  30.6 KB  |  824 lines

  1. (c)  Copyright 1991 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and is provided "as is" without warranty of any kind, either expressed
  4. or implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7.  
  8. Making Your Windows More Shiny and Manageable
  9.  
  10.  
  11. By Ewout Walraven
  12.  
  13.  
  14.  
  15. The Intuition window paradigm has features that make it easy for the user to
  16. manage windows.  The user can select, move, resize, close, or depth arrange
  17. their windows on any screen so they can quickly get to the window they need.
  18. With 2.0 and a little work, the tools are there to give the user even greater
  19. powers to manage and organize their working environment.
  20.  
  21. This article addresses some release 2.0 system features which can further
  22. integrate your application's window into the 2.0 environment.  These features
  23. include public screens, the zoom gadget, AppIcons, and AppMenuItems, which
  24. are not discussed in detail here.  For more information on public screens and
  25. the zoom gadget, see the intuition.library Autodocs and the article ``An
  26. Introduction to V36 Screens and Windows'' from the September/October issue of
  27. Amiga Mail.  For more information on AppIcons and AppMenuItems, see the
  28. workbench.library Autodocs and the article ``AppWindows, AppIcons, and
  29. AppMenuItems'', which is in this issue of Amiga Mail.
  30.  
  31.  
  32. Public Screens
  33.  
  34. The public screens introduced in 2.0 make it possible for the user to open
  35. several screens where different applications can open windows.  If an
  36. application allows the user to choose the public screen on which it opens its
  37. window, the user can more easily organize their working environment.  They
  38. can spread their work across several public screens allowing them to use the
  39. screen that has the palette or resolution best suited to their purposes.
  40. This also buys the user more room for windows.  In case one screen gets too
  41. cluttered with windows, the user can open an application's window on a
  42. different public screen.
  43.  
  44. There are number of ways you can support public screens.  If your application
  45. uses command line options or reads tooltypes, it can support the PUBSCREEN
  46. keyword as a command line argument or tooltype.  This lets the user indicate
  47. the name of the public screen on which your windows should open.  For
  48. example, if some developer wrote a new shell that supported public screens,
  49. the shell's icon could have the following tooltype in its icon:
  50.  
  51. PUBSCREEN=<pubscreenname>
  52.  
  53. which tells the shell to open its window on the public screen named
  54. pubscreenname.
  55.  
  56. If an application supports ARexx, it can support a JUMPTOSCREEN command that
  57. tells it to move, or jump, its window to a specific public screen.  The
  58. application would open a new window on the public screen named in the
  59. JUMPTOSCREEN command and closes its old window.  Your application can even
  60. provide a jump-to-next-screen gadget, that makes the window jump to the next
  61. public screen.  By using the intuition.library NextPubScreen(), your
  62. application can get the name of the next screen in the public screen list,
  63. close its window on the current screen and re-open it on the next.
  64.  
  65. The example program jumpy.c opens a window which jumps from one screen to
  66. another when the user clicks the jump gadget.
  67.  
  68.  
  69. Zooming
  70.  
  71. A very simple, but convenient feature you can ask the system to add to your
  72. window is a zoom gadget.  A zoom gadget allows the user to toggle between two
  73. window sizes simply by clicking on a gadget.  In 2.0, a window gets a zoom
  74. gadget automatically when it has both a sizing and depth gadget, although you
  75. don't need a sizing gadget to get a zoom gadget.  You can ask for a zoom
  76. gadget by specifying the WA_Zoom tag when opening the window.  The WA_Zoom
  77. tag takes an array of four WORDs, describing the initial LeftEdge, TopEdge,
  78. Width, and Height values of the window's alternate dimensions and position.
  79. Because such a window has no sizing gadget, the user can only toggle between
  80. two window sizes, the original size and the alternate size specified with the
  81. WA_Zoom tag.  The preference editors use this feature to toggle between a
  82. full-sized window and a window displaying only the title bar.  The example
  83. zoom.c shows how easy it is to implement this feature.
  84.  
  85.  
  86. Iconifying
  87.  
  88. Although the zoom gadget provides a pseudo-iconifying feature, the
  89. Workbench's AppIcon and AppMenuItem features provide true iconification.  To
  90. iconify a window, create the AppIcon or AppMenuItem that will replace the
  91. window.  Next, store the state of the window (like its current position or
  92. the state of its gadgets), so the application can restore the window to its
  93. original state when the application reopens it.  Now close the window.
  94. Because it is possible for the AddAppIcon() or AddAppMenuItem() function to
  95. fail, It is important to create the AppIcon or AppMenuItem before closing the
  96. window.  If an application closes the window first and Workbench can't create
  97. the AppIcon or AppMenuItem, there will be no AppIcon or AppMenuItem for the
  98. user to select to uniconify the window.
  99.  
  100. An application can set up a gadget or menu item so the user can tell the
  101. application to iconify the window.  If the application uses a gadget to
  102. iconify, it should not put the gadget in the window border because there is
  103. no standard ``look'' to what an iconify gadget should look like.
  104.  
  105. The last example, hide.c, shows how to use AppIcons and AppMenuItems to
  106. iconify a window.
  107.  
  108.  
  109.  
  110. ;/* Jumpy.c - Execute me to compile me with Lattice 5.10a
  111. LC -b1 -cfistq -v -y -j73 Jumpy.c
  112. Blink FROM LIB:c.o,Jumpy.o TO Jumpy LIBRARY LIB:LC.lib,LIB:Amiga.lib
  113. quit
  114. */
  115.  
  116. #include <intuition/intuition.h>
  117. #include <intuition/screens.h>
  118. #include <graphics/text.h>
  119. #include <libraries/gadtools.h>
  120.  
  121. #ifdef LATTICE
  122. #include <string.h>
  123. #include <clib/alib_protos.h>
  124. #include <clib/exec_protos.h>
  125. #include <clib/intuition_protos.h>
  126. #include <clib/gadtools_protos.h>
  127. #include <clib/graphics_protos.h>
  128. /* disable SAS/C CTRL-C handing */
  129. int             CXBRK(void)
  130. {
  131.     return (0);
  132. }
  133. int             chkabort(void)
  134. {
  135.     return (0);
  136. }
  137.  
  138. #endif
  139.  
  140. struct IntuitionBase *IntuitionBase;
  141. struct GfxBase *GfxBase;
  142. struct Library *GadToolsBase;
  143. struct Library *IconBase;
  144. struct Library *CxBase;
  145.  
  146. LONG            main(LONG, UBYTE **);
  147.  
  148. LONG
  149. main(LONG argc, UBYTE ** argv)
  150. {
  151.     struct Window       *window;
  152.     struct IntuiMessage *imsg;
  153.     struct Gadget       *gadgetcontext;
  154.     struct Gadget       *gadget, *nextscreengadget;
  155.     struct NewGadget     ng;
  156.     struct TextExtent    textextent;
  157.     UWORD                left, top;
  158.     void                *visualinfo;
  159.     UBYTE               *startupname;
  160.     UBYTE                namebuffer[MAXPUBSCREENNAME];
  161.     UBYTE              **tooltypes;
  162.     BOOL                 ABORT = FALSE;
  163.  
  164.     if (IntuitionBase = OpenLibrary("intuition.library", 37))
  165.     {
  166.         /* Open GfxBase to use TextExtent() so we can handle proportional fonts */
  167.         if (GfxBase = OpenLibrary("graphics.library", 37))
  168.         {
  169.             if (GadToolsBase = OpenLibrary("gadtools.library", 37))
  170.             {
  171.  
  172.                 /*
  173.                  * Open commodities & icon.library so we can use ArgArray
  174.                  * functions
  175.                  */
  176.                 if (CxBase = OpenLibrary("commodities.library", 37))
  177.                 {
  178.                     if (IconBase = OpenLibrary("icon.library", 37))
  179.                     {
  180.                         left = 50;
  181.                         top = 50;                /* Initial offset */
  182.                         /* Note that these are functions in amiga.lib */
  183.                         if (tooltypes = ArgArrayInit(argc, argv))
  184.                         {
  185.                             startupname =
  186.                                 ArgString(tooltypes, "PUBSCREEN", "Workbench");
  187.                             strcpy(namebuffer, startupname);
  188.                             ArgArrayDone();
  189.                         }
  190.                         else
  191.                             strcpy(namebuffer, "Workbench");
  192.                         do
  193.                         {
  194.                             /* open a window with tags */
  195.                             /* no NewWindow structure, tags only */
  196.                             if (window = OpenWindowTags(NULL,
  197.                                         /* Open at far left corner */
  198.                                         WA_Left,  left,
  199.                                         WA_Top,   top,
  200.                                         WA_Width, 150,
  201.                                         WA_Height, 80,
  202.                                         WA_Title, (LONG) "jumpy",
  203.                                         WA_PubScreenName, (LONG) namebuffer,
  204.                                         /* if no pubscreen with this name exists... */
  205.                                         WA_PubScreenFallBack, TRUE,
  206.                                         /* ...fall back on default pubscreen */
  207.                                         WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET |
  208.                                             WFLG_CLOSEGADGET | WFLG_ACTIVATE |
  209.                                             WFLG_SMART_REFRESH | WFLG_NOCAREREFRESH,
  210.                                         WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
  211.                                         TAG_DONE))
  212.                             {
  213.  
  214.                                 /*
  215.                                  * Get the visual info gadtools needs for the
  216.                                  * screen we opened on
  217.                                  */
  218.                                 if (visualinfo = GetVisualInfoA(window->WScreen, NULL))
  219.                                 {
  220.  
  221.                                     /*
  222.                                      * Create a simple gadtools button and sort
  223.                                      * of lay it out. Note this doesn't do any
  224.                                      * checking for legal (window) dimensions.
  225.                                      */
  226.                                     if (gadget = CreateContext(&gadgetcontext))
  227.                                     {
  228.  
  229.                                         /*
  230.                                          * Use TextExtent to handle
  231.                                          * proportional fonts
  232.                                          */
  233.                                         TextExtent(&(window->WScreen->RastPort),
  234.                                                    "Jump", 4, &textextent);
  235.                                         ng.ng_Width = textextent.te_Width + 8;
  236.                                         ng.ng_LeftEdge = (window->Width / 2) -
  237.                                                           (ng.ng_Width / 2);
  238.                                         ng.ng_Height = textextent.te_Height + 4;
  239.                                         ng.ng_TopEdge = (
  240.                                             (window->Height - window->BorderTop -
  241.                                                 window->BorderBottom) / 2) +
  242.                                             (ng.ng_Height / 2);
  243.                                         ng.ng_TextAttr = window->WScreen->Font;
  244.                                         ng.ng_GadgetText = "Jump";
  245.                                         ng.ng_VisualInfo = visualinfo;
  246.                                         ng.ng_GadgetID = 1;
  247.                                         ng.ng_Flags = PLACETEXT_IN;
  248.                                         nextscreengadget = gadget =
  249.                                             CreateGadget(BUTTON_KIND, gadget, &ng,
  250.                                                          TAG_END);
  251.                                         AddGList(window, gadget, -1, -1, NULL);
  252.                                         RefreshGList(gadget, window, NULL, -1);
  253.                                         GT_RefreshWindow(window, NULL);
  254.  
  255.                                         WaitPort(window->UserPort);
  256.                                         while (imsg = (struct IntuiMessage *)
  257.                                             GetMsg(window->UserPort))
  258.                                         {
  259.                                             if (imsg->Class == IDCMP_CLOSEWINDOW)
  260.                                                 ABORT = TRUE;
  261.                                             else if (imsg->Class = IDCMP_GADGETUP)
  262.                                                 NextPubScreen(window->WScreen,
  263.                                                               namebuffer);
  264.                                             ReplyMsg((struct Message *) imsg);
  265.                                         }
  266.                                         RemoveGadget(window, nextscreengadget);
  267.                                         FreeGadgets(gadgetcontext);
  268.                                     }
  269.                                     FreeVisualInfo(visualinfo);
  270.                                 }
  271.                                 left = window->LeftEdge;
  272.                                 top = window->TopEdge;
  273.                                 CloseWindow(window);
  274.                             }
  275.                         } while (ABORT == FALSE);
  276.  
  277.                         CloseLibrary(IconBase);
  278.                     }
  279.                     CloseLibrary(CxBase);
  280.                 }
  281.                 CloseLibrary(GadToolsBase);
  282.             }
  283.             CloseLibrary(GfxBase);
  284.         }
  285.         CloseLibrary(IntuitionBase);
  286.     }
  287.     return (0);
  288. }
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341. ;/* Zoom.c - Execute me to compile me with Lattice 5.10a
  342. LC -b1 -cfistq -v -y -j73 Zoom.c
  343. Blink FROM LIB:c.o,Zoom.o TO Zoom LIBRARY LIB:LC.lib,LIB:Amiga.lib
  344. quit
  345. */
  346. #include <intuition/intuition.h>
  347. #include <intuition/screens.h>
  348.  
  349. #ifdef LATTICE
  350. #include <clib/exec_protos.h>
  351. #include <clib/intuition_protos.h>
  352. /* disable SAS/C CTRL-C handing */
  353.  
  354. int             CXBRK(void)
  355. {
  356.     return (0);
  357. }
  358.  
  359. int             chkabort(void)
  360. {
  361.     return (0);
  362. }
  363. #endif
  364.  
  365. struct IntuitionBase *IntuitionBase;
  366.  
  367. LONG            main(void);
  368.  
  369. LONG main(void)
  370. {
  371.     struct IBox     ibox;    /* The structure we'll use to specify the zoom'ed
  372.                               * dimension. */
  373.     struct Screen  *wbscreen;
  374.     struct Window  *window;
  375.     struct Message *msg;     /* Make this an IntuiMessage when you want to use
  376.                               * it */
  377.  
  378.  
  379.     if (IntuitionBase = OpenLibrary("intuition.library", 37))
  380.     {
  381.  
  382.         /* Lock workbench screen so we can watch it closely */
  383.         if (wbscreen = LockPubScreen("Workbench"))
  384.         {
  385.  
  386.             /*
  387.              * Generate a nice position for the zoom'ed window. Note that this
  388.              * specifies the INITIAL position of the window. Since we don't
  389.              * have a size gadget, the user can't change the height and width,
  390.              * but the offset is changed as the window is dragged.
  391.              */
  392.             ibox.Left = wbscreen->Width - 180;   /* far right corner */
  393.             ibox.Top = wbscreen->BarHeight + 1;  /* Just below screen bar */
  394.             ibox.Width = 180;
  395.             /* ght of the window topborder */
  396.             ibox.Height = wbscreen->WBorTop + wbscreen->Font->ta_YSize + 1;
  397.  
  398.             /* open a window with tags */
  399.             if (window = OpenWindowTags(NULL,    /* no NewWindow structure,
  400.                                                   * tags only */
  401.                                         WA_Left, 0,     /* Open at far left
  402.                                                          * corner */
  403.                                         WA_Top, wbscreen->BarHeight + 1,
  404.                                         WA_Width, 200,
  405.                                         WA_Height, 100,
  406.                                         WA_Title, (LONG) "A simple window",
  407.                 WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
  408.                      WFLG_ACTIVATE | WFLG_SIMPLE_REFRESH | WFLG_NOCAREREFRESH,
  409.  
  410.                                         /* Only interested in closewindow      */
  411.                                         WA_IDCMP, IDCMP_CLOSEWINDOW,
  412.  
  413.                                         /* pass the alternate zoom dimension   */
  414.                                         WA_Zoom, (LONG) & ibox,
  415.  
  416.                                         TAG_DONE))
  417.             {
  418.  
  419.                 /* And just wait for windowclose */
  420.                 WaitPort(window->UserPort);
  421.                 /* clear the message port */
  422.                 while (msg = GetMsg(window->UserPort))
  423.                     ReplyMsg(msg);
  424.  
  425.                 CloseWindow(window);
  426.             }
  427.             UnlockPubScreen(NULL, wbscreen);
  428.         }
  429.         CloseLibrary(IntuitionBase);
  430.     }
  431. }
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495. /*
  496.  * Hide.h
  497. */
  498.  
  499. UWORD chip      ImageI1Data[] =
  500. {
  501. /* Plane 0 */
  502.     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8208, 0x0000, 0x0000,
  503.     0x8208, 0x7FFF, 0xFFFF, 0xFEF8, 0x4000, 0x0000, 0x00A8, 0x4000,
  504.     0x0000, 0x0048, 0x4000, 0x0000, 0x00A8, 0x4000, 0x0000, 0x0048,
  505.     0x4000, 0x0000, 0x00A8, 0x4000, 0x0000, 0x0008, 0x4000, 0x0000,
  506.     0x0008, 0x4000, 0x0000, 0x00E8, 0x4000, 0x0000, 0x0008, 0xFFFF,
  507.     0xFFFF, 0xFFF8,
  508. /* Plane 1 */
  509.     0xFFFF, 0xFFFF, 0xFFF8, 0x8000, 0x0000, 0x4100, 0x8000, 0x0000,
  510.     0x4100, 0x8000, 0x0000, 0x0100, 0xC000, 0x0000, 0x0110, 0xC000,
  511.     0x0000, 0x0110, 0xC000, 0x0000, 0x0110, 0xC000, 0x0000, 0x0110,
  512.     0xC000, 0x0000, 0x0110, 0xC000, 0x0000, 0x0110, 0xC000, 0x0000,
  513.     0x0110, 0xC000, 0x0000, 0x0110, 0xFFFF, 0xFFFF, 0xFFF0, 0x0000,
  514.     0x0000, 0x0000,
  515. };
  516.  
  517. struct Image    ImageI1 =
  518. {
  519.     0, 0,                    /* Upper left corner */
  520.     45, 14, 2,               /* Width, Height, Depth */
  521.     ImageI1Data,             /* Image data */
  522.     0x0003, 0x0000,          /* PlanePick, PlaneOnOff */
  523.     NULL                     /* Next image */
  524. };
  525.  
  526. UWORD chip      ImageI2Data[] =
  527. {
  528. /* Plane 0 */
  529.     0x0000, 0x0000, 0x0000, 0x7FFF, 0xFFFF, 0xBEF8, 0x7FFF, 0xFFFF,
  530.     0xBEF8, 0x7FFF, 0xFFFF, 0xFEF8, 0x4000, 0x0000, 0x00E8, 0x4000,
  531.     0x0000, 0x00E8, 0x4000, 0x0000, 0x00E8, 0x4000, 0x0000, 0x00E8,
  532.     0x4000, 0x0000, 0x00E8, 0x4000, 0x0000, 0x00A8, 0x4000, 0x0000,
  533.     0x00A8, 0x4000, 0x0000, 0x00E8, 0x4000, 0x0000, 0x0008, 0xFFFF,
  534.     0xFFFF, 0xFFF8,
  535. /* Plane 1 */
  536.     0xFFFF, 0xFFFF, 0xFFF8, 0xFFFF, 0xFFFF, 0x7DF0, 0xFFFF, 0xFFFF,
  537.     0x7DF0, 0x8000, 0x0000, 0x0100, 0xC000, 0x0000, 0x0150, 0xC000,
  538.     0x0000, 0x01B0, 0xC000, 0x0000, 0x0150, 0xC000, 0x0000, 0x01B0,
  539.     0xC000, 0x0000, 0x0150, 0xC000, 0x0000, 0x01F0, 0xC000, 0x0000,
  540.     0x01F0, 0xC000, 0x0000, 0x0110, 0xFFFF, 0xFFFF, 0xFFF0, 0x0000,
  541.     0x0000, 0x0000,
  542. };
  543.  
  544. struct Image    ImageI2 =
  545. {
  546.     0, 0,                    /* Upper left corner */
  547.     45, 14, 2,               /* Width, Height, Depth */
  548.     ImageI2Data,             /* Image data */
  549.     0x0003, 0x0000,          /* PlanePick, PlaneOnOff */
  550.     NULL                     /* Next image */
  551. };
  552.  
  553. struct DiskObject AppIconDObj =
  554. {
  555.     0,
  556.     0,
  557.     {                        /* Embedded Gadget Structure */
  558.         NULL,                /* Next Gadget Pointer */
  559.         0, 0, 45, 15,        /* Left,Top,Width,Height */
  560.         GFLG_GADGHIMAGE,
  561.         0,                   /* Activation Flags */
  562.         0,                   /* Gadget Type */
  563.         (APTR) & ImageI1,    /* Render Image */
  564.         (APTR) & ImageI2,    /* Select Image */
  565.         NULL,                /* Gadget Text */
  566.         NULL,                /* Mutual Exclude */
  567.         NULL,                /* Special Info */
  568.         0,                   /* Gadget ID */
  569.         NULL,                /* User Data */
  570.     },
  571.     0,                       /* Icon Type */
  572.     NULL,                    /* Default Tool */
  573.     NULL,                    /* Tool Type Array */
  574.     NO_ICON_POSITION,        /* Current X */
  575.     NO_ICON_POSITION,        /* Current Y */
  576.     NULL,                    /* Drawer Structure */
  577.     NULL,                    /* Tool Window */
  578.     0                        /* Stack Size */
  579. };
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587. ;/* Hide.c - Execute me to compile me with Lattice 5.10a
  588. LC -b1 -cfistq -v -y -j73 Hide.c
  589. Blink FROM LIB:c.o,Hide.o TO Hide LIBRARY LIB:LC.lib,LIB:Amiga.lib
  590. quit
  591. */
  592.  
  593. #include <intuition/intuition.h>
  594. #include <intuition/screens.h>
  595. #include <graphics/text.h>
  596. #include <libraries/gadtools.h>
  597. #include <workbench/startup.h>
  598. #include <workbench/workbench.h>
  599. #include "hide.h"
  600.  
  601. #ifdef LATTICE
  602. #include <clib/alib_protos.h>
  603. #include <clib/exec_protos.h>
  604. #include <clib/intuition_protos.h>
  605. #include <clib/gadtools_protos.h>
  606. #include <clib/graphics_protos.h>
  607. #include <clib/wb_protos.h>
  608.  
  609. /* disable SAS/C CTRL-C handing */
  610. int             CXBRK(void)
  611. {
  612.     return (0);
  613. }
  614. int             chkabort(void)
  615. {
  616.     return (0);
  617. }
  618.  
  619. #endif
  620.  
  621. struct IntuitionBase *IntuitionBase;
  622. struct GfxBase *GfxBase;
  623. struct WorkbenchBase *WorkbenchBase;
  624. struct Library *GadToolsBase;
  625.  
  626. LONG            main(void);
  627.  
  628. LONG
  629. main(void)
  630. {
  631.     struct Window  *window;
  632.     struct IntuiMessage *imsg;
  633.     struct Gadget  *gadgetcontext;
  634.     struct Gadget  *gadget, *hidegadget;
  635.     struct MsgPort *appport;
  636.     struct NewGadget ng;
  637.     struct TextExtent textextent;
  638.     struct AppIcon *appicon = NULL;
  639.     struct AppMessage *appmsg;
  640.     UWORD           left, top;
  641.     void           *visualinfo;
  642.     ULONG           signal, windowsignal, waitmask;
  643.     BOOL            ABORT = FALSE;
  644.     BOOL            CONTINUE, ICONIFY;
  645.  
  646.     if (IntuitionBase = OpenLibrary("intuition.library", 37))
  647.     {
  648.         /* Open GfxBase to use TextExtent() so we can handle proportional fonts */
  649.         if (GfxBase = OpenLibrary("graphics.library", 37))
  650.         {
  651.             /* Open gadtools for that lonely gadget */
  652.             if (GadToolsBase = OpenLibrary("gadtools.library", 37))
  653.             {
  654.                 if (WorkbenchBase = OpenLibrary("workbench.library", 37))
  655.                 {
  656.                     /* Message to receive appmessage on */
  657.                     if (appport = CreateMsgPort())
  658.                     {
  659.                         /* open a window with tags */
  660.                         left = top = 50;
  661.                         do
  662.                         {
  663.                             /* no NewWindow structure, tags only */
  664.                             if (window = OpenWindowTags(NULL,
  665.                                          /* Open at far left corner */
  666.                                          WA_Left, left,
  667.                                          WA_Top, top,
  668.                                          WA_Width, 150,
  669.                                          WA_Height, 80,
  670.                                          WA_Title, (LONG) "hide",
  671.                                          WA_Flags, WFLG_DRAGBAR |
  672.                                              WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
  673.                                              WFLG_ACTIVATE | WFLG_SMART_REFRESH |
  674.                                              WFLG_NOCAREREFRESH,
  675.                                          WA_IDCMP,
  676.                                              IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
  677.                                          TAG_DONE))
  678.                             {
  679.                                 windowsignal = 1L << window->UserPort->mp_SigBit;
  680.                                 /*
  681.                                  * Get the visual info gadtools needs for the
  682.                                  * screen we opened on
  683.                                  */
  684.                                 if (visualinfo = GetVisualInfoA(window->WScreen, NULL))
  685.                                 {
  686.  
  687.                                     /*
  688.                                      * Create a simple gadtools button and sort
  689.                                      * of lay it out
  690.                                      */
  691.                                     if (gadget = CreateContext(&gadgetcontext))
  692.                                     {
  693.  
  694.                                         /*
  695.                                          * Use TextExtent to handle
  696.                                          * proportional fonts
  697.                                          */
  698.                                         TextExtent(&(window->WScreen->RastPort),
  699.                                                    "Hide", 4, &textextent);
  700.                                         ng.ng_Width = textextent.te_Width + 8;
  701.                                         ng.ng_LeftEdge = (window->Width / 2)
  702.                                                               - (ng.ng_Width / 2);
  703.                                         ng.ng_Height = textextent.te_Height + 4;
  704.                                         ng.ng_TopEdge = (
  705.                                             (window->Height - window->BorderTop
  706.                                                 - window->BorderBottom) / 2)
  707.                                             + (ng.ng_Height / 2);
  708.                                         ng.ng_TextAttr = window->WScreen->Font;
  709.                                         ng.ng_GadgetText = "Hide";
  710.                                         ng.ng_VisualInfo = visualinfo;
  711.                                         ng.ng_GadgetID = 1;
  712.                                         ng.ng_Flags = PLACETEXT_IN;
  713.                                         hidegadget = gadget =
  714.                                             CreateGadget(BUTTON_KIND, gadget,
  715.                                                          &ng, TAG_END);
  716.                                         AddGList(window, gadget, -1, -1, NULL);
  717.                                         RefreshGList(gadget, window, NULL, -1);
  718.                                         GT_RefreshWindow(window, NULL);
  719.  
  720.                                         CONTINUE = TRUE;
  721.                                         waitmask = windowsignal|
  722.                                                        1L << appport->mp_SigBit;
  723.                                         do
  724.                                         {
  725.                                             signal = Wait(waitmask);
  726.  
  727.                                           if (signal & windowsignal)
  728.                                             {
  729.                                                 while (imsg = (struct IntuiMessage *)
  730.                                                     GetMsg(window->UserPort))
  731.                                                 {
  732.                                                     if (imsg->Class ==
  733.                                                             IDCMP_CLOSEWINDOW)
  734.                                                     {
  735.                                                         ABORT = TRUE;
  736.                                                         CONTINUE = FALSE;
  737.                                                         ICONIFY = FALSE;
  738.                                                     }
  739.                                                     else
  740.                                                     if (imsg->Class == IDCMP_GADGETUP)
  741.                                                         ICONIFY = TRUE;
  742.                                                     ReplyMsg((struct Message *) imsg);
  743.                                                 }
  744.                                             }
  745.                                             if (signal & (1L << appport->mp_SigBit))
  746.                                             {
  747.                                                 while (appmsg = (struct AppMessage *)
  748.                                                     GetMsg(appport))
  749.                                                 {
  750.  
  751.                                                     /*
  752.                                                      * If am->NumArgs is zero
  753.                                                      * the user double-clicked
  754.                                                      * on our icon, otherwise
  755.                                                      * one or more icons were
  756.                                                      * dropped on top of it.
  757.                                                      */
  758.                                                     if (appmsg->am_NumArgs == 0)
  759.                                                     {
  760.                                                         RemoveAppIcon(appicon);
  761.                                                         CONTINUE = FALSE;
  762.                                                     }
  763.                                                     ReplyMsg(
  764.                                                         (struct Message *) appmsg);
  765.                                                 }
  766.                                             }
  767.                                             if (ICONIFY)
  768.                                             {
  769.  
  770.                                                 /*
  771.                                                  * Add appicon, close window if
  772.                                                  * succesful
  773.                                                  */
  774.                                                 appicon = AddAppIcon(1, NULL, "Hide",
  775.                                                     appport, NULL, &AppIconDObj, NULL);
  776.                                                 if (appicon == NULL)
  777.                                                 {
  778.                                                     DisplayBeep(window->WScreen);
  779.                                                 }
  780.                                                 else
  781.                                                 {
  782.                                                     RemoveGadget(window, hidegadget);
  783.                                                     left = window->LeftEdge;
  784.                                                     top = window->TopEdge;
  785.                                                     CloseWindow(window);
  786.                                                     window = NULL;
  787.                                                     /* there is no window
  788.                                                      * message port anymore */
  789.                                                     waitmask =
  790.                                                         1L << appport->mp_SigBit;
  791.                                                 }
  792.                                                 ICONIFY = FALSE;
  793.                                             }
  794.                                         } while (CONTINUE == TRUE);
  795.                                         if (window)
  796.                                             RemoveGadget(window, hidegadget);
  797.                                         FreeGadgets(gadgetcontext);
  798.                                     }
  799.                                     FreeVisualInfo(visualinfo);
  800.                                 }
  801.  
  802.  
  803.                                 if (window)
  804.                                 {
  805.                                     left = window->LeftEdge;
  806.                                     top = window->TopEdge;
  807.                                     CloseWindow(window);
  808.                                 }
  809.                             }
  810.                         } while (ABORT == FALSE);
  811.                         DeleteMsgPort(appport);
  812.                     }
  813.                     CloseLibrary(WorkbenchBase);
  814.                 }
  815.                 CloseLibrary(GadToolsBase);
  816.             }
  817.             CloseLibrary(GfxBase);
  818.         }
  819.         CloseLibrary(IntuitionBase);
  820.     }
  821.     return (0);
  822. }
  823.  
  824.